﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
using Portal.Environment;
using Portal.Language;
using Portal.Interface;

namespace Portal.CMS
{
    public class NewsHistory : WebPart
    {
        public override string WebPartId
        {
            get
            {
                return "NewsHistory";
            }
        }


        public override bool IsMainWebPart
        {
            get
            {
                return true;
            }
        }

        public override bool RunStandalone
        {
            get
            {
                return true;
            }
        }

        public override string Title
        {
            get
            {
                return ResourceBLL.GetText(WebPartId,"Title","Lịch sử sửa chữa tin tức");
            }
        }

        public override string Description
        {
            get
            {
                return ResourceBLL.GetText(WebPartId,"Description","");
            }
        }


        public override WebPartInt[] SubWebParts
        {
            get
            {
                WebPartInt[] SubWebParts = new WebPartInt[]{
                    
                };
                return SubWebParts;
            }
        }


        public override string RenderWebPart(LoadParamCls loadParamCls)
        {
            try
            {
                AjaxPro.Utility.RegisterTypeForAjax(typeof(NewsHistory));
                //Environments.CheckWebPartAllow(WebPartId, true);
                Environments.CheckSessionTimeOut(true);

                string NewsId = (string)Environments.Request("NewsId");
                string RetNewsHistory =
                    //Portal.Environment.WebPartUtilities.AttachJavascript(new std, "NewsHistory.js") +
                    "<div class=cssNewsHistoryMain>" +
                    "   <div id=divNewsHistoryContent>" + GetNewsHistory("vie", NewsId) + "</div>" +
                    "</div>";
                RetNewsHistory = Environments.GetFormDialog(RetNewsHistory, Title);
                return RetNewsHistory;
            }
            catch (Exception ex)
            {
                return ex.Message.ToString();
            }
        }

      
        [AjaxPro.AjaxMethod]
        public string GetNewsHistory(string belongSite,string NewsId)
        {
            try
            {
                Environment.Environments.CheckSessionTimeOut(true);
                DataTable dtNewsHistory = new NewsBLL().ReadingHistory(NewsId);
                string RetNewsHistory = "<table>" +
                                        " <tr>" +
                                        "   <th>" + ResourceBLL.GetText(WebPartId, "Index", "#") + "</th>" +
                                        "   <th>" + ResourceBLL.GetText(WebPartId, "Time", "Thời gian") + "</th>" +
                                        "   <th>" + ResourceBLL.GetText(WebPartId, "Account", "Tài khoản") + "</th>" +
                                        "   <th>" + ResourceBLL.GetText(WebPartId, "FullName", "Tên tài khoản") + "</th>" +
                                        " </tr>";
                for (int iIndex = 0; iIndex < dtNewsHistory.Rows.Count; iIndex++)
                {
                    DateTime LogDate = (DateTime)dtNewsHistory.Rows[iIndex]["LogDate"];
                    string LogUser = (string)dtNewsHistory.Rows[iIndex]["LogUser"];
                    string LogFullName = (string)dtNewsHistory.Rows[iIndex]["LogFullName"];
                    RetNewsHistory +=   " <tr>" +
                                        "   <td>" +(iIndex+1) + "</td>" +
                                        "   <td>" + LogDate.ToString("dd/MM/yyyy HH:mm") + "</td>" +
                                        "   <td>" + LogUser + "</td>" +
                                        "   <td>" + LogFullName + "</td>" +
                                        " </tr>";
                }
                RetNewsHistory += "</table>";
                return RetNewsHistory;
            }
            catch (Exception ex)
            {
                return ex.Message.ToString();
            }
        }
    }
}
